#!/bin/bash

# Function to send ggpush command and check for response
send_ggpush() {
  # Send ggpush command and capture the output using perl for timeout
  output=$(perl -e 'alarm shift @ARGV; exec @ARGV' 2 ggpush)

  # Check if the command was successful and returned output
  if [ -n "$output" ]; then
    echo "ggpush command returned output:"
    echo "$output"
    return 0
  else
    echo "ggpush command did not return output within 3 seconds."
    return 1
  fi
}

# Loop to send ggpush command every 10 seconds
while true; do
  send_ggpush
  if [ $? -eq 0 ]; then
    break
  fi
  sleep 3
done

echo "Script terminated."
